﻿using OpenCvSharp;
using Sdcb.PaddleInference;
using Sdcb.PaddleOCR;
using Sdcb.PaddleOCR.Models.Local;
using System.Diagnostics;

var model = LocalFullModels.ChineseV4;
var st = new Stopwatch();

using PaddleOcrAll all = new(model, PaddleDevice.Onnx())
{
    AllowRotateDetection = false, /* 允许识别有角度的文字 */
    Enable180Classification = false, /* 允许识别旋转角度大于90度的文字 */
};

void OcrTest(string filename)
{
    // Load local file by following code:
    using Mat src = Cv2.ImRead(filename, ImreadModes.Color);

    st.Start();
    PaddleOcrResult result = all.Run(src);
    st.Stop();
    Console.WriteLine("Detected all texts: \n" + result.Text);
    foreach (PaddleOcrResultRegion region in result.Regions)
    {
        Console.WriteLine($"Text: {region.Text}, Score: {region.Score}, RectCenter: {region.Rect.Center}, RectSize: {region.Rect.Size}, Angle: {region.Rect.Angle}");
    }
    
    Console.WriteLine($"识别时长: {st.Elapsed}");
}

for (int i = 1; i <= 6; i++)
{
    OcrTest($"./images/test{i}.png");
}